<?php
/**
 * Nordic Repository
 * 
 * LICENSE
 * 
 * The new BSD license is applied on this source-file. For further
 * information please visit http://license.nordic-dev.de/newbsd.txt
 * or send an email to andre.moelle@gmail.com.
 */

/**
 * Necessary includes.
 */
require_once 'Nordic/Pagebar/Exception.php';
require_once 'Nordic/Pagebar/Behaviour.php';

/**
 * Element of the pagebar.
 * 
 * The advantage of this class is that it can contain various
 * information about the type. Therefore you do not have to care
 * about complex array-structures.
 * 
 * @category   Nordic
 * @package    Nordic_Pagebar
 * @copyright  2007 Nordic Development
 * @license    http://license.nordic-dev.de/newbsd.txt (New-BSD license)
 * @author     Andre Moelle <andre.moelle@gmail.com>
 * @version    $Id: Element.php 3 2007-07-08 09:21:42Z andre.moelle $
 */
class Nordic_Pagebar_Element
{
	/**
	 * Behaviour which contains all the applied behaviours.
	 * 
	 * @var Nordic_Pagebar_Behaviour
	 */
	private $_behaviour;
	
	/**
	 * Type of the element.
	 * 
	 * This integer is based upon the constants in Nordic_Pagebar.
	 * 
	 * @var integer
	 */
	private $_type;
	
	/**
	 * Page-number.
	 * 
	 * @var integer
	 */
	private $_value;
	
	/**
	 * Constructor.
	 * 
	 * @param integer $value page-number
	 * @param integer $type type of the element.
	 */
	public function __construct (Nordic_Pagebar_Behaviour $behaviour, $value, $type = 0)
	{
		$this->_value = $value;
		$this->_type = $type;
		$this->_behaviour = $behaviour;
	}
	
	/**
	 * Magic call-method. This is used to redirect the "is*"-methods.
	 * 
	 * @param string $method method-name
	 * @param array $args arguments
	 * @return boolean
	 */
	public function __call ($method, $args)
	{
		if(substr($method, 0, 2) != 'is')
		{
			throw new Nordic_Pagebar_Exception('No method "' . $method . '"');
		}
		
		$strict = (isset($args[0]) ? (bool)$args[0] : false);
		$alias = substr($method, 2);
		
		return $this->_behaviour->is($alias, $this, $strict);
	}
	
	/**
	 * If casted to a string, the integer is returned as string.
	 * 
	 * @param void
	 * @return string
	 */
	public function __toString ()
	{
		return (string)$this->_value;
	}
	
	/**
	 * @see Nordic_Pagebar_Element::getType()
	 */
	public function getType ()
	{
		return $this->_type;
	}
}
?>